package com.gyf.test;

import com.gyf.dao.IUserDao;
import com.gyf.model.User;
import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public class Lesson05 {

    @Test
    public void test1() throws Exception {

       /*//1.创建数据源
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql:///spring_day04");
        dataSource.setUsername("root");
        dataSource.setPassword("123456");

        //2.创建jdbcTemplate
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);

        jdbcTemplate.update("update t_user set username = ? where id = ?","zzz",1);
*/

       //jdbcTemplate放在dao中

        ApplicationContext context = new ClassPathXmlApplicationContext("beans05.xml");
        IUserDao userDao = (IUserDao) context.getBean("userDao");
        User user = new User();
        user.setUsername("gyf");
        user.setPassword("123");
        userDao.add(user);
    }
}
